<include file="public@storage"/>
<link rel="stylesheet" href="__STATIC__/storage/js/feed/feed.css"/>

</head>
<body>
<div class="container body-content" style="margin-top:20px;width: 100%">
    <div class="panel panel-info" style="margin-bottom: 0.5rem">
        <div class="panel-heading">
            <span id="storageName">
            <button id = "return" style="background-color:rgb(51, 122, 183);border: none ;display: none" onclick="history.go(-1)"><span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span></button>
            {$storageInfo[0]['name']}</span>料站表管理
        </div>

        <input type="hidden" id="storageUuid" value="{$storageInfo[0]['uuid']}">
        <input type="hidden" id="returnValue" value="{$history}">
        <div class="panel-body">
            <div class="row">
                <div class="col-sm-12">
                    <div id="toolbar" class="btn-group">
                        <select id="selectStorage" class="btn btn-info" style="margin-left: 1rem; width: 10rem"
                                onchange="changeStorage()">
                            <option value="">请选择仓库</option>
                            <volist id="uuid" name="storageInfo" id="value">
                                <option value="{$value['uuid']}">{$value['name']}</option>
                            </volist>
                        </select>
                    </div>
                    <table id="table"></table>
                </div>
            </div>
        </div>
    </div>
    <div class='qrcode' id="qrcode" style="display: none"></div>
</div>
</body>
<script src="__STATIC__/js/qrcode.min.js"></script>
<script src="__STATIC__/storage/js/common/selectStorage.js"></script>
<script>
    var storageUuid = $("#storageUuid").val();
    var returnValue = $("#returnValue").val();

    $(function () {
        init();
    });

    function init() {
        var url = "{:url('/storage/Feed/getFeedStation')}?&storageUuid=" + storageUuid;
        var columns = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {
                title: 'uuid',
                field: 'uuid',
                visible: false
            },
            {
                title: '工单号',
                field: 'feed_id',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '工单量',
                field: 'feed_num',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '生效时间',
                field: 'effect_time',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '所属仓库',
                field: 'name',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '创建时间',
                field: 'time',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '状态',
                field: 'status',
                align: "center",
                filter: {
                    type: 'select',
                    data: [{id: '', text: ''}, {id: 0, text: '未开始'}, {id: 1, text: '生产中'}, {id: 2, text: '已完成'}]
                },
                formatter: function (value) {
                    var html = '';
                    if (value === 0) {
                        html+=' <label class = "undo">' + '未开始' + '</label>';
                    } else if (value === 1){
                        html+=' <label class = "unfinished">' + '生产中' + '</label>';
                    }
                    else if(value === 2){
                        html+=' <label class = "finished">' + '已完成' + '</label>';
                    }
                    return html;
                }
            },
            {
                title: '操作',
                field: 'feed_id',
                align: "center",
                valign: 'middle',
                formatter: selectList

            }
        ];
        initTable(url, columns, 'server', InitSubTable);
        setColumn();
    }


    InitSubTable = function (index, row, $detail) {
        var tableId = "cur_table_"+index;
        $detail.html('<table id="'+ tableId+ '"></table>').find('table');
        var url = '{:url("storage/Feed/getFeedStationDetail")}?feedUuid=' + row.uuid;
        var column = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {
                title: 'uuid',
                field: 'uuid',
                align: "center",
                visible: false
            },

            {
                title: '机器号',
                field: 'machine_id',
                align: "center",
                filter: {
                    type: 'input'
                }
            },

            {
                title: '料位号',
                field: 'seat_code',
                align: "center",
                filter: {
                    type: 'input'
                }
            },



            {
                title: '物料id',
                field: 'sub_materiel_id',
                align: "center",

                filter: {
                    type: 'input'
                },
            },

            {
                title: '单位用量',
                field: 'used_num',
                align: "center",

                filter: {
                    type: 'input'
                },
            },
            {
                title: '总用量',
                field: 'total_count',
                align: "center",

                filter: {
                    type: 'input'
                },
            },

            {
                title: '已发数量',
                field: 'sent_count',
                align: "center",

                filter: {
                    type: 'input'
                },
            },
            {
                title: '损耗',
                field: 'waste',
                align: "center",

                filter: {
                    type: 'input'
                },
            },
            {
                title: '供料器尺寸',
                field: 'size',
                align: "center",

                filter: {
                    type: 'input'
                },
            },



            {
                title: '状态',
                field: 'status',
                align: "center",
                filter: {
                    type: 'input'
                }, formatter: function (value) {
                    if (value === 1) {
                        return '未完成';
                    } else {
                        return '已完成';
                    }
                }

            },
            {
                title: '备注',
                field: 'mark',
                align: "center",

                filter: {
                    type: 'input'
                },
            },

        ];
        initSubTable(tableId,url, column, 'server');
    };

    function setColumn() {
        if (storageUuid === '') {
            $('#table').bootstrapTable('showColumn', 'name');
        } else {
            $('#table').bootstrapTable('hideColumn', 'name');
        }
    }

    //生成二维码
    printCode = function (that) {
        var feedId = $(that).data('feed');
        var code = $('.qrcode');
        $('.qrcode canvas').remove();
        $('.qrcode img').remove();
        $('.qrcode p').remove();
        var qrcode = new QRCode(document.getElementById('qrcode'), {
            text: feedId,
            width: 256,
            height: 256
        });
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['300px', '300px'],
            skin: '', //没有背景色
            shadeClose: true,
            content: $('.qrcode')
        });
        var html = "<p class='q-qrcode'>" + feedId + "</p>";
        code.append(html);
    };

    selectList = function (value, row) {
        var feedId;
        feedId = row.feed_id;
        var html =  '<a class="print" onclick="printCode(this)" href="javascript:;" data-feed ="' + feedId + '"  style="text-decoration:none">二维码</a>';
        return html;
    }
</script>
</html>